home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / rpccmd / rpccmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-10  |  8.4 KB  |  318 lines

  1. /* 
  2.  * rpccmd.c --
  3.  *
  4.  *    User interface to RPC related commands of the Fs_Command system call.
  5.  *
  6.  * Copyright (C) 1986 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/cmds/rpccmd/RCS/rpccmd.c,v 1.7 92/07/10 14:57:28 kupfer Exp $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21. #include <sprite.h>
  22. #include <status.h>
  23. #include <option.h>
  24. #include <stdio.h>
  25. #include <fs.h>
  26. #include <fsCmd.h>
  27. #include <sysStats.h>
  28. #include <rpc.h>
  29. #include <host.h>
  30.  
  31. /*
  32.  * Command line options.
  33.  */
  34.  
  35. int    rpcEnable = -1;
  36. int    rpcDebug = -1;
  37. int    rpcTracing = -1;
  38. int    rpc_NoTimeouts = -1;
  39. int    rpcClientHist = -1;
  40. int    rpcServerHist = -1;
  41. Boolean    resetClientHist = FALSE;
  42. Boolean    resetServerHist = FALSE;
  43. char    *rpcEchoHost = (char *)0;
  44. int    blockSize = 32;
  45. int    rpcMaxServers = -1;
  46. int    rpcNumServers = -1;
  47. int    rpcNegAcks = -1;
  48. int    rpcChannelNegAcks = -1;
  49. int    rpcNumNackBufs = -1;
  50. int    numEchoes = 100;
  51. int    sanityChecks = -1;
  52.  
  53. Option optionArray[] = {
  54.     {OPT_TRUE, "on", (Address) &rpcEnable, 
  55.     "\tAllow servicing of RPC requests."},
  56.     {OPT_FALSE, "off", (Address) &rpcEnable, 
  57.     "\tTurn off servicing of RPC requests."},
  58.     {OPT_STRING, "ping", (Address) &rpcEchoHost, 
  59.     "\tRPC test against the specified host."},
  60.     {OPT_INT, "b", (Address) &blockSize, 
  61.     "\tBlock size to send in RPC test."},
  62.     {OPT_INT, "t", (Address) &rpcTracing, 
  63.     "\tSet rpc tracing flag."},
  64.     {OPT_INT, "T", (Address) &rpc_NoTimeouts, 
  65.     "\tSet rpc no timeouts flag."},
  66.     {OPT_INT, "D", (Address) &rpcDebug, 
  67.     "\tSet rpc debug flag."},
  68.     {OPT_INT, "C", (Address) &rpcClientHist, 
  69.     "\tSet client histogram flag."},
  70.     {OPT_INT, "S", (Address) &rpcServerHist, 
  71.     "\tSet server histogram flag."},
  72.     {OPT_TRUE, "Creset", (Address) &resetClientHist, 
  73.     "\tReset client RPC histograms."},
  74.     {OPT_TRUE, "Sreset", (Address) &resetServerHist, 
  75.     "\tReset server RPC histograms."},
  76.     {OPT_INT, "maxServers", (Address) &rpcMaxServers,
  77.     "\tSet the maximum number of allowed rpc server processes."},
  78.     {OPT_INT, "numServers", (Address) &rpcNumServers,
  79.     "\tCreate more rpc servers until this number exists."},
  80.     {OPT_TRUE, "negAcksOn", (Address) &rpcNegAcks,
  81.     "\tTurn on negative acknowledgements on a server."},
  82.     {OPT_FALSE, "negAcksOff", (Address) &rpcNegAcks,
  83.     "\tTurn off negative acknowledgements on a server (default)."},
  84.     {OPT_INT, "numNackBufs", (Address) &rpcNumNackBufs,
  85.     "\tMake sure this number of negative ack buffers exists."},
  86.     {OPT_TRUE, "channelNegAcksOn", (Address) &rpcChannelNegAcks,
  87.     "\tSet the client policy for handling negative acks to ramp down number of channels."},
  88.     {OPT_FALSE, "channelNegAcksOff", (Address) &rpcChannelNegAcks,
  89.     "\tSet the client policy for handling negative acks to the default backoff policy."},
  90.     {OPT_INT, "numPings", (Address) &numEchoes,
  91.     "\tNumber of pings to send."},
  92.     {OPT_INT, "sanity", (Address)&sanityChecks,
  93.     "\tTurn off/on rpc sanity checks."},
  94.  
  95. };
  96. int numOptions = sizeof(optionArray) / sizeof(Option);
  97.  
  98. /* forward references: */
  99.  
  100. static void ResetClientHist();
  101. static void ResetServerHist();
  102. ReturnStatus SetFlag();
  103.  
  104.  
  105. /*
  106.  *----------------------------------------------------------------------
  107.  *
  108.  * main --
  109.  *
  110.  *    Collects arguments and branch to the code for the fs command.
  111.  *
  112.  * Results:
  113.  *    None.
  114.  *
  115.  * Side effects:
  116.  *    Calls Fs_Command...
  117.  *
  118.  *----------------------------------------------------------------------
  119.  */
  120. main(argc, argv)
  121.     int argc;
  122.     char *argv[];
  123. {
  124.     register ReturnStatus status = SUCCESS;    /* status of system calls */
  125.  
  126.     argc = Opt_Parse(argc, argv, optionArray, numOptions, 0);
  127.  
  128.     /*
  129.      * Set various rpc system flags.  The Fs_Command system call returns
  130.      * the old value of the flag in place of the value passed in.
  131.      */
  132.     if (rpcEnable != -1) {
  133.     status = Sys_Stats(SYS_RPC_ENABLE_SERVICE, rpcEnable, NIL);
  134.     }
  135.     if (rpcTracing != -1) {
  136.     status = SetFlag(FS_SET_RPC_TRACING, rpcTracing, "RPC tracing");
  137.     }
  138.     if (rpc_NoTimeouts != -1) {
  139.     status = SetFlag(FS_SET_RPC_NO_TIMEOUTS, rpc_NoTimeouts,
  140.                         "No RPC timeouts");
  141.     }
  142.     if (rpcDebug != -1) {
  143.     status = SetFlag(FS_SET_RPC_DEBUG, rpcDebug, "RPC debug prints");
  144.     }
  145.     if (rpcClientHist != -1) {
  146.     status = SetFlag(FS_SET_RPC_CLIENT_HIST, rpcClientHist,
  147.                          "Client RPC timing histograms");
  148.     }
  149.     if (rpcServerHist != -1) {
  150.     status = SetFlag(FS_SET_RPC_SERVER_HIST, rpcServerHist,
  151.                         "Server RPC timing histograms");
  152.     }
  153.     if (resetClientHist) {
  154.     ResetClientHist();
  155.     }
  156.     if (resetServerHist) {
  157.     ResetServerHist();
  158.     }
  159.     if (rpcMaxServers != -1) {
  160.     status = Sys_Stats(SYS_RPC_SET_MAX, rpcMaxServers, NIL);
  161.     }
  162.     if (rpcNumServers != -1) {
  163.     status = Sys_Stats(SYS_RPC_SET_NUM, rpcNumServers, NIL);
  164.     }
  165.     if (rpcNegAcks != -1) {
  166.     status = Sys_Stats(SYS_RPC_NEG_ACKS, rpcNegAcks, NIL);
  167.     }
  168.     if (rpcNumNackBufs != -1) {
  169.     status = Sys_Stats(SYS_RPC_NUM_NACK_BUFS, rpcNumNackBufs, NIL);
  170.     }
  171.     if (rpcChannelNegAcks != -1) {
  172.     status = Sys_Stats(SYS_RPC_CHANNEL_NEG_ACKS, rpcChannelNegAcks, NIL);
  173.     }
  174.     if (rpcEchoHost != (char *)0) {
  175.     status = RpcEcho(rpcEchoHost);
  176.     }
  177.     if (sanityChecks != -1) {
  178.     status = Sys_Stats(SYS_RPC_SANITY_CHECK, sanityChecks, NIL);
  179.     }
  180.     exit(status);
  181. }
  182.  
  183. RpcEcho(server)
  184.     char *server;
  185. {
  186.     Host_Entry *entryPtr;
  187.     int serverID;
  188.     int myID;
  189.     int error;
  190.     char buffer[16 * 1024];
  191.     Time deltaTime;
  192.  
  193.     entryPtr = Host_ByName(server);
  194.     if (entryPtr == (Host_Entry *) NULL) {
  195.     fprintf(stderr, "Unable to get host number for host '%s'\n",
  196.                server);
  197.     exit(1);
  198.     }
  199.     serverID = entryPtr->id;
  200.  
  201.     error = Proc_GetHostIDs((int *) NULL, &myID);
  202.     if (error != SUCCESS) {
  203.     perror( "Proc_GetHostIDs");
  204.     exit(error);
  205.     }
  206.     if (myID == serverID) {
  207.     fprintf(stderr, "Unable to send RPC to yourself.\n");
  208.     exit(1);
  209.     }
  210.     error = DoTest(TEST_RPC_SEND, serverID, numEchoes, blockSize, buffer,
  211.         buffer, &deltaTime);
  212.     if (error != SUCCESS) {
  213.     Stat_PrintMsg(error, "RPC failed:");
  214.     } else {
  215.     printf("Send %d bytes %d.%06d sec\n", blockSize, deltaTime.seconds,
  216.         deltaTime.microseconds);
  217.     }
  218.     return(error);
  219. }
  220. ReturnStatus
  221. DoTest(command, serverID, numEchoes, size, inDataBuffer, outDataBuffer, timePtr)
  222.     int command;
  223.     int serverID;
  224.     int numEchoes;
  225.     int size;
  226.     Address inDataBuffer;
  227.     Address outDataBuffer;
  228.     Time *timePtr;
  229. {
  230.     Rpc_EchoArgs echoArgs;
  231.     ReturnStatus error;
  232.  
  233.     echoArgs.serverID = serverID;
  234.     echoArgs.n = numEchoes;
  235.     echoArgs.size = size;
  236.     echoArgs.inDataPtr = inDataBuffer;
  237.     echoArgs.outDataPtr = outDataBuffer;
  238.     echoArgs.deltaTimePtr = timePtr;
  239.     error = Test_Rpc(command, &echoArgs);
  240.  
  241.     return(error);
  242. }
  243.  
  244. ReturnStatus
  245. SetFlag(command, value, comment)
  246.     int command;        /* Argument to Fs_Command */
  247.     int value;            /* Value for flag */
  248.     char *comment;        /* For Io_Print */
  249. {
  250.     register int newValue;
  251.     register ReturnStatus status;
  252.  
  253.     newValue = value;
  254.     status = Fs_Command(command, sizeof(int), (Address) &value);
  255.     printf("%s %s, was %s\n", comment,
  256.              newValue ? "on" : "off",
  257.              value ? "on" : "off");
  258.     return(status);
  259. }
  260.  
  261.  
  262. /*
  263.  *----------------------------------------------------------------------
  264.  *
  265.  * ResetClientHist --
  266.  *
  267.  *    Reset the client-side histograms.
  268.  *
  269.  * Results:
  270.  *    None.
  271.  *
  272.  * Side effects:
  273.  *    None.
  274.  *
  275.  *----------------------------------------------------------------------
  276.  */
  277.  
  278. static void
  279. ResetClientHist()
  280. {
  281.     ReturnStatus status;
  282.  
  283.     status = Sys_Stats(SYS_RPC_CLIENT_HIST, 0, NULL);
  284.     if (status != SUCCESS) {
  285.     fprintf(stderr, "Can't reset client RPC histograms: %s\n",
  286.         Stat_GetMsg(status));
  287.     }
  288. }
  289.  
  290.  
  291. /*
  292.  *----------------------------------------------------------------------
  293.  *
  294.  * ResetServerHist --
  295.  *
  296.  *    Reset the server-side histograms.
  297.  *
  298.  * Results:
  299.  *    None.
  300.  *
  301.  * Side effects:
  302.  *    None.
  303.  *
  304.  *----------------------------------------------------------------------
  305.  */
  306.  
  307. static void
  308. ResetServerHist()
  309. {
  310.     ReturnStatus status;
  311.  
  312.     status = Sys_Stats(SYS_RPC_SERVER_HIST, 0, NULL);
  313.     if (status != SUCCESS) {
  314.     fprintf(stderr, "Can't reset server RPC histograms: %s\n",
  315.         Stat_GetMsg(status));
  316.     }
  317. }
  318.